package com.drguo.higouguo.service.impl;

import java.util.List;

import com.drguo.higouguo.dao.CategoryDao;
import com.drguo.higouguo.dao.GoodsDao;
import com.drguo.higouguo.entity.Category;
import com.drguo.higouguo.service.CategoryService;
import com.drguo.higouguo.utils.GuoUtil;

public class CategoryServiceImpl implements CategoryService {
	private CategoryDao categoryDao;
	private GoodsDao goodsDao;
	
	
	//增加商品类别
	@Override
	public void addCategory(Category category) {
		category.setId(GuoUtil.getId());
		categoryDao.addCategory(category);
	}
	//商品类别列表
	@Override
	public List<Category> getCategories() {
		return categoryDao.getCategories();
		
	}
	//首页商品类别
	@Override
	public List<Category> getCategoriesForIndex() {
		List<Category> categories = categoryDao.getCategories();
		for(Category category : categories){
			category.setGoodses(goodsDao.getGoodsByCateId(category.getId(), 4));//每个类别显示4个商品（一排）
		}
		return categories;
	}

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	public GoodsDao getGoodsDao() {
		return goodsDao;
	}
	public void setGoodsDao(GoodsDao goodsDao) {
		this.goodsDao = goodsDao;
	}


}
